import java.util.Objects;

public class SellTicket {
    public static void main(String[] args) {
        Sell sell1=new Sell();
        Sell sell2=new Sell();
        Sell sell3=new Sell();
        new Thread(sell1).start();
        new Thread(sell2).start();
        new Thread(sell3).start();


    }



    static class Sell implements Runnable{
        private static int tickeNum=100;//售票100张
        Sell sell;
        boolean flag=true;


        public synchronized void by(Sell sell){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (tickeNum==0){
                flag=false;
                System.out.println("没票了");
                return;
            }else {
                synchronized (this){
                    tickeNum--;
                    System.out.println(Thread.currentThread().getName()+"   剩下"+this.tickeNum+"张票");
                }
            }
        }

        public void run(){
            while (flag){
                by(sell);
            }
        }
    }
}
